package com.lry.filter.client;

import com.lry.common.CommonConstants;
import com.lry.filter.server.ServerFilter;
import com.lry.protocol.RpcInvocation;
import com.lry.protocol.RpcMessage;
import com.lry.rpc.config.RpcReferenceBean;
import com.lry.rpc.netty.client.ClientCache;
import com.lry.spi.LoadLevel;
import com.lry.util.StringUtils;
import lombok.extern.slf4j.Slf4j;

@LoadLevel(name = "token")
@Slf4j
public class ClientTokenFilter implements ClientFilter {

    @Override
    public void filter(RpcMessage rpcMessage) {
        if(rpcMessage.getBody() instanceof RpcInvocation) {
            RpcInvocation rpcInvocation = (RpcInvocation) rpcMessage.getBody();
            RpcReferenceBean referenceBean = ClientCache.getReferenceBean(rpcInvocation);
            rpcMessage.addHead(CommonConstants.TOKEN,referenceBean.getToken());
        }
    }
}
